#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time
from datetime import datetime
from datetime import timedelta

class DateUtil:

    @staticmethod
    def getNowDate(timeFormat = "%Y-%m-%d %H:%M:%S"):
        return datetime.now().strftime(timeFormat)

    @staticmethod
    def getNowTimeStamp():
        return int(time.time())

    # date = "2018-01-11"
    @staticmethod
    def getWeekDay(date):
        date = datetime.datetime.strptime(date, '%Y-%m-%d')
        weekDayDict = {
            0:"Mon",
            1:"Tues",
            2:"Wed",
            3:"Thur",
            4:"Fri",
            5:"Sat",
            6:"Sun"
        }
        day = date.weekday()
        return weekDayDict[day]

    # date = "2018-01-11"
    @staticmethod
    def getMonth(date):
        date = datetime.datetime.strptime(date, '%Y-%m-%d')
        monthDict = {
            1:"Jan",
            2:"Feb",
            3:"Mar",
            4:"Apr",
            5:"May",
            6:"Jun",
            7:"Jul",
            8:"Aug",
            9:"Sept",
            10:"Oct",
            11:"Nov",
            12:"Dec"
        }
        return monthDict[date.month]

    @staticmethod
    def timeStampToDate(timestamp, timeFormat = "%Y-%m-%d %H:%M:%S"):
        if len(str(timestamp)) == 13 :
            timestamp = timestamp / 1000
        timeLocal = time.localtime(timestamp)
        return time.strftime(timeFormat, timeLocal)

    @staticmethod
    def dateToTimeStamp(date):
        timeArray = time.strptime(str(date), "%Y-%m-%d %H:%M:%S")
        return int(time.mktime(timeArray))

    @staticmethod
    def dateSub(timeFormat = "%Y-%m-%d %H:%M:%S"):
        # timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
        date = datetime.now() - timedelta(days=1)
        return date.strftime(timeFormat)

    @staticmethod
    def dateAdd(timeFormat = "%Y-%m-%d %H:%M:%S"):
        # timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
        date = datetime.now() + timedelta(days=1)
        return date.strftime(timeFormat)

if __name__ == "__main__":
    print DateUtil.getNowDate()
